<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/16
 * Time: 19:45
 */

namespace app\admin\controller;


use app\admin\model\SetType;
use app\common\controller\ReturnCode;
use think\Controller;
use think\Request;
use app\admin\model\Set as Se;
class Set extends Controller
{
    function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this -> aid = $request -> param('aid');
        $this -> token = $request -> param('token');
        $this -> page = $request -> param('page');
        $this -> typeID = $request -> param('type_id');
        $this -> name = $request -> param('name');
        $this -> setId = $request -> param('setId');
        $this -> hasToken  = hasToken($this -> aid, $this -> token);
    }
    //------------------------------------------规格
    //列表
    public function speclist(){
        if(!isset($this -> aid) || empty($this -> token)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $res = db('set_spec')->field("spec_id,spec_name,FROM_UNIXTIME(add_time,'%Y-%m-%d %H:%i:%s') as add_time")->select();
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0],'data' => $res]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //添加
    public function specadd(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> name)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $data = ['spec_name' => $this -> name,'add_time' => time(),'update_time' =>time()];
            $where = ['spec_name' => $this -> name];
            $has = db('set_spec') -> where($where)->find();
            if($has){
                return json(['status' => 23 , 'msg' => ReturnCode::$return_code[23]]);
            }
            $res = db('set_spec')->insert($data);
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //详情
    public function specinfo(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $where = ['spec_id' => $this -> setId];
            $res = db('set_spec')->where($where)->find();
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0],'data' => $res]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //修改
    public function specup(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId) || empty($this -> name)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $data = ['spec_name' => $this -> name,'update_time' =>time()];
            $where = ['spec_name' => $this -> name];
            $where2 = ['spec_id' => $this -> setId];
            $has = db('set_spec') -> where($where)->find();
            if($has){
                return json(['status' => 23 , 'msg' => ReturnCode::$return_code[23]]);
            }
            $res = db('set_spec')->where($where2)->update($data);
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //删除
    public function specdel(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){

            $where2 = ['spec_id' => $this -> setId];
            $res = db('set_spec')->where($where2)->delete();

            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }


    //------------------------------------------加料
    //列表
    public function feedlist(){
        if(!isset($this -> aid) || empty($this -> token)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $res = db('set_feed')->field("feed_id,feed_name,FROM_UNIXTIME(add_time,'%Y-%m-%d %H:%i:%s') as add_time")->select();
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0],'data' => $res]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //添加
    public function feedadd(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> name)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $data = ['feed_name' => $this -> name,'add_time' => time(),'update_time' =>time()];
            $where = ['feed_name' => $this -> name];
            $has = db('set_feed') -> where($where)->find();
            if($has){
                return json(['status' => 23 , 'msg' => ReturnCode::$return_code[23]]);
            }
            $res = db('set_feed')->insert($data);
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //详情
    public function feedinfo(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $where = ['feed_id' => $this -> setId];
            $res = db('set_feed')->where($where)->find();
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0],'data' => $res]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //修改
    public function feedup(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId) || empty($this -> name)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $data = ['feed_name' => $this -> name,'update_time' =>time()];
            $where = ['feed_name' => $this -> name];
            $where2 = ['feed_id' => $this -> setId];
            $has = db('set_feed') -> where($where)->find();
            if($has){
                return json(['status' => 23 , 'msg' => ReturnCode::$return_code[23]]);
            }
            $res = db('set_feed')->where($where2)->update($data);
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //删除
    public function feeddel(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){

            $where2 = ['feed_id' => $this -> setId];
            $res = db('set_feed')->where($where2)->delete();

            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }


    //------------------------------------------茶底
    //列表
    public function dregslist(){
        if(!isset($this -> aid) || empty($this -> token)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $res = db('set_dregs')->field("dregs_id,dregs_name,FROM_UNIXTIME(add_time,'%Y-%m-%d %H:%i:%s') as add_time")->select();
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0],'data' => $res]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //添加
    public function dregsadd(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> name)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $data = ['dregs_name' => $this -> name,'add_time' => time(),'update_time' =>time()];
            $where = ['dregs_name' => $this -> name];
            $has = db('set_dregs') -> where($where)->find();
            if($has){
                return json(['status' => 23 , 'msg' => ReturnCode::$return_code[23]]);
            }
            $res = db('set_dregs')->insert($data);
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //详情
    public function dregsinfo(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $where = ['dregs_id' => $this -> setId];
            $res = db('set_dregs')->where($where)->find();
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0],'data' => $res]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //修改
    public function dregsup(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId) || empty($this -> name)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $data = ['dregs_name' => $this -> name,'update_time' =>time()];
            $where = ['dregs_name' => $this -> name];
            $where2 = ['dregs_id' => $this -> setId];
            $has = db('set_dregs') -> where($where)->find();
            if($has){
                return json(['status' => 23 , 'msg' => ReturnCode::$return_code[23]]);
            }
            $res = db('set_dregs')->where($where2)->update($data);
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //删除
    public function dregsdel(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){

            $where2 = ['dregs_id' => $this -> setId];
            $res = db('set_dregs')->where($where2)->delete();

            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }


    //------------------------------------------糖度
    //列表
    public function sugarlist(){
        if(!isset($this -> aid) || empty($this -> token)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $res = db('set_sugar')->field("sugar_id,sugar_name,FROM_UNIXTIME(add_time,'%Y-%m-%d %H:%i:%s') as add_time")->select();
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0],'data' => $res]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //添加
    public function sugaradd(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> name)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $data = ['sugar_name' => $this -> name,'add_time' => time(),'update_time' =>time()];
            $where = ['sugar_name' => $this -> name];
            $has = db('set_sugar') -> where($where)->find();
            if($has){
                return json(['status' => 23 , 'msg' => ReturnCode::$return_code[23]]);
            }
            $res = db('set_sugar')->insert($data);
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //详情
    public function sugarinfo(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $where = ['sugar_id' => $this -> setId];
            $res = db('set_sugar')->where($where)->find();
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0],'data' => $res]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //修改
    public function sugarup(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId) || empty($this -> name)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $data = ['sugar_name' => $this -> name,'update_time' =>time()];
            $where = ['sugar_name' => $this -> name];
            $where2 = ['sugar_id' => $this -> setId];
            $has = db('set_sugar') -> where($where)->find();
            if($has){
                return json(['status' => 23 , 'msg' => ReturnCode::$return_code[23]]);
            }
            $res = db('set_sugar')->where($where2)->update($data);
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //删除
    public function sugardel(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){

            $where2 = ['sugar_id' => $this -> setId];
            $res = db('set_sugar')->where($where2)->delete();

            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }



    //------------------------------------------口味
    //列表
        public function flavorlist(){
            if(!isset($this -> aid) || empty($this -> token)){
                return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
            }
            if($this -> hasToken){
                $res = db('set_flavor')->field("flavor_id,flavor_name,FROM_UNIXTIME(add_time,'%Y-%m-%d %H:%i:%s') as add_time")->select();
                if($res){
                    return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0],'data' => $res]);
                }
                return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
            }
            return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
        }
        //添加
        public function flavoradd(){
            if(!isset($this -> aid) || empty($this -> token) || empty($this -> name)){
                return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
            }
            if($this -> hasToken){
                $data = ['flavor_name' => $this -> name,'add_time' => time(),'update_time' =>time()];
                $where = ['flavor_name' => $this -> name];
                $has = db('set_flavor') -> where($where)->find();
                if($has){
                    return json(['status' => 23 , 'msg' => ReturnCode::$return_code[23]]);
                }
                $res = db('set_flavor')->insert($data);
                if($res){
                    return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
                }
                return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
            }
            return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
        }
        //详情
        public function flavorinfo(){
            if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId)){
                return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
            }
            if($this -> hasToken){
                $where = ['flavor_id' => $this -> setId];
                $res = db('set_flavor')->where($where)->find();
                if($res){
                    return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0],'data' => $res]);
                }
                return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
            }
            return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
        }
        //修改
        public function flavorup(){
            if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId) || empty($this -> name)){
                return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
            }
            if($this -> hasToken){
                $data = ['flavor_name' => $this -> name,'update_time' =>time()];
                $where = ['flavor_name' => $this -> name];
                $where2 = ['flavor_id' => $this -> setId];
                $has = db('set_flavor') -> where($where)->find();
                if($has){
                    return json(['status' => 23 , 'msg' => ReturnCode::$return_code[23]]);
                }
                $res = db('set_flavor')->where($where2)->update($data);
                if($res){
                    return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
                }
                return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
            }
            return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
        }
        //删除
        public function flavordel(){
            if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId)){
                return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
            }
            if($this -> hasToken){

                $where2 = ['flavor_id' => $this -> setId];
                $res = db('set_flavor')->where($where2)->delete();

                if($res){
                    return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
                }
                return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
            }
            return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
        }


    //------------------------------------------状态
    //列表
    public function statelist(){
        if(!isset($this -> aid) || empty($this -> token)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $res = db('set_state')->field("state_id,state_name,FROM_UNIXTIME(add_time,'%Y-%m-%d %H:%i:%s') as add_time")->select();
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0],'data' => $res]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //添加
    public function stateadd(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> name)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $data = ['state_name' => $this -> name,'add_time' => time(),'update_time' =>time()];
            $where = ['state_name' => $this -> name];
            $has = db('set_state') -> where($where)->find();
            if($has){
                return json(['status' => 23 , 'msg' => ReturnCode::$return_code[23]]);
            }
            $res = db('set_state')->insert($data);
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //详情
    public function stateinfo(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $where = ['state_id' => $this -> setId];
            $res = db('set_state')->where($where)->find();
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0],'data' => $res]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //修改
    public function stateup(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId) || empty($this -> name)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $data = ['state_name' => $this -> name,'update_time' =>time()];
            $where = ['state_name' => $this -> name];
            $where2 = ['state_id' => $this -> setId];
            $has = db('set_state') -> where($where)->find();
            if($has){
                return json(['status' => 23 , 'msg' => ReturnCode::$return_code[23]]);
            }
            $res = db('set_state')->where($where2)->update($data);
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //删除
    public function statedel(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){

            $where2 = ['state_id' => $this -> setId];
            $res = db('set_state')->where($where2)->delete();

            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }


    //------------------------------------------温度
    //列表
    public function temlist(){
        if(!isset($this -> aid) || empty($this -> token)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $res = db('set_tem')->field("tem_id,tem_name,FROM_UNIXTIME(add_time,'%Y-%m-%d %H:%i:%s') as add_time")->select();
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0],'data' => $res]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //添加
    public function temadd(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> name)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $data = ['tem_name' => $this -> name,'add_time' => time(),'update_time' =>time()];
            $where = ['tem_name' => $this -> name];
            $has = db('set_tem') -> where($where)->find();
            if($has){
                return json(['status' => 23 , 'msg' => ReturnCode::$return_code[23]]);
            }
            $res = db('set_tem')->insert($data);
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //详情
    public function teminfo(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $where = ['tem_id' => $this -> setId];
            $res = db('set_tem')->where($where)->find();
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0],'data' => $res]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //修改
    public function temup(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId) || empty($this -> name)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){
            $data = ['tem_name' => $this -> name,'update_time' =>time()];
            $where = ['tem_name' => $this -> name];
            $where2 = ['tem_id' => $this -> setId];
            $has = db('set_tem') -> where($where)->find();
            if($has){
                return json(['status' => 23 , 'msg' => ReturnCode::$return_code[23]]);
            }
            $res = db('set_tem')->where($where2)->update($data);
            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }
    //删除
    public function temdel(){
        if(!isset($this -> aid) || empty($this -> token) || empty($this -> setId)){
            return json(['status' => 2,'msg' => ReturnCode::$return_code[2]]);
        }
        if($this -> hasToken){

            $where2 = ['tem_id' => $this -> setId];
            $res = db('set_tem')->where($where2)->delete();

            if($res){
                return json(['status' => 0 , 'msg' => ReturnCode::$return_code[0]]);
            }
            return json(['status' => 1 , 'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status' => 3 , 'msg' => ReturnCode::$return_code[3]]);
    }

    /**
     * 新表
     * 大类
     */
    public function settype(){
        if(!isset($this->aid) || empty($this->token)){
            return json(['status' => 2, 'msg'=> ReturnCode::$return_code[2]]);
        }
        if($this->hasToken){
            $res = Se::all();
            if($res){
                return json(['status' => 0,'msg' => ReturnCode::$return_code[0],'data'=>$res]);
            }
            return json(['status' => 1,'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status'=> 3, 'msg'=> ReturnCode::$return_code[3]]);
    }
    //添加
    //详情
    //修改
    //删除

    /**
     * 大类详情
     */
    public function typeinfo(){
        if(!isset($this->aid) || empty($this->token) || empty($this->typeID)){
            return json(['status' => 2, 'msg'=> ReturnCode::$return_code[2]]);
        }
        if($this->hasToken){
            $where = ['set_id' => $this->typeID];
            $res = SetType::where($where)->paginate(10,false,['page'=>$this->page]);
            if($res){
                return json(['status' => 0,'msg' => ReturnCode::$return_code[0],'data'=>$res]);
            }
            return json(['status' => 1,'msg' => ReturnCode::$return_code[1]]);
        }
        return json(['status'=> 3, 'msg'=> ReturnCode::$return_code[3]]);
    }
    //添加
    //详情
    //修改
    //删除
}